package com.example.sunsg.okhttptest.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.example.sunsg.okhttptest.util.Util;

/**
 * Created by sunsg on 16/3/7.
 */
public class PreviewImage implements Parcelable {
    private static final String PREFI= "http://";
    private int width;
    private int height;
    private String path;
    private boolean isChecked;

    public PreviewImage() {
    }

    public PreviewImage(int width, int height, String path,boolean isChecked) {
        this.width = width;
        this.height = height;
        this.path = path;
        this.isChecked = isChecked;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    /**
     * 是否是网络图片url
     */
    public boolean isHttpUrl() {
        return Util.isHttpUrl(path);
    }

    /**
     * 是否是本地图片路径
     * @return
     */
    public boolean isLocalFilePath(){
        return Util.isLocalFilePath(path);
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.width);
        dest.writeInt(this.height);
        dest.writeString(this.path);
        dest.writeByte(isChecked ? (byte) 1 : (byte) 0);
    }

    protected PreviewImage(Parcel in) {
        this.width = in.readInt();
        this.height = in.readInt();
        this.path = in.readString();
        this.isChecked = in.readByte() != 0;
    }

    public static final Creator<PreviewImage> CREATOR = new Creator<PreviewImage>() {
        public PreviewImage createFromParcel(Parcel source) {
            return new PreviewImage(source);
        }

        public PreviewImage[] newArray(int size) {
            return new PreviewImage[size];
        }
    };
}
